#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e3 + 10;
int f[20];
int w[N], v[N], n;
int main()
{
	cin >> n;
	memset(f, 0x3f, sizeof(f));
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
		string s;
		cin >> s;
		//cout << s << endl;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == 'A')v[i] += 1;
			else if (s[j] == 'B')v[i] += 2;
			else v[i] += 4;
		}
		//f[v[i]] = w[i];
		//cout << "v==" << v[i] << endl;
	}
	f[0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 7; j >= 0; j--) {
			f[j | v[i]] = min(f[j | v[i]], f[i] + w[i]);
			/*cout << "v[i]==" << v[i] << endl;
			cout <<"---"<< (j | v[i]) << endl;
			cout << "f[j]==" << f[j | v[i]] << endl;*/
		}
	}
	if (f[7] == 0x3f3f3f3f)cout << -1 << endl;
	else cout << f[7] << endl;
	return 0;
}